import { createRouter, createWebHistory } from 'vue-router'
import Register from "@/views/register/Register.vue";
import Login from "@/views/login/Login.vue";
import Home from "@/views/home/Home.vue";
import Dashboard from "@/views/Dashboard.vue";
import Test from "@/views/test/Test.vue";
import TextToImage from "@/views/text2image/TextToImage.vue";
import TranslateLang from "@/views/translate_lang/TranslateLang.vue";


const routes = [
    {
        path: '/',
        name: 'startLogin',
        component: Login
    },
    {
        path: '/register',
        name: 'Register',
        component: Register
    },
    {
        path: '/login',
        name: 'Login',
        component: Login
        // 可添加子级路由 children:[{path: '/children_url/:id/:title/:content?', name: 'Login_children', component: Login_children, props: true}]

        //路由的写法可参考以下两种：
        //第一种写法:将路由收到的所有params参数作为props传给路由组件
        // props:true,
        //第二种写法:函数写法，可以自己决定将什么作为props给路由组件
        /* props(route){
            return route.query
        } */
    },
    {
        path: '/home',
        name: 'Home',
        component: Home
    },
    {
        path: '/dashboard',
        name: 'Dashboard',
        component: Dashboard
    },
    {
        path: '/text_to_image',
        name: 'TextToImage',
        component: TextToImage
    },
    {
        path: '/translate',
        name: 'Translate',
        component: TranslateLang
    },
    {
        path: '/test',
        name: 'Test',
        component: Test
    },
    // 其他路由...
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

// token路由守卫
// router.beforeEach((to, from, next) =>{
//     const token = localStorage.getItem('token')
//     if (to.name !=='Login' && !token) next({name: 'Login'})
//     else next()
// })

export default router